﻿#pragma once
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>
#include <QThread>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QMouseEvent>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include "json.h"
#include "clog.h"
#include "conf.h"
#include "chatsocket.h"
#include "mainwidget.h"
#include <QMessageBox>
#include <QSignalMapper>
#include <QListWidget>
#include <QListWidgetItem>
#include <QEvent>
#include <QVector>
#include "mydelegate.h"
#include "chatdb.h"
#include "chatwidget.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class ChatSocket;
class Widget : public QWidget
{
    Q_OBJECT
public:
    ~Widget();
    static Widget* getInstance();
    QString getID();
    void fillUID(QString uid);
private:
    Widget(QWidget *parent = nullptr);
    void setShadow();
    void beautification();//美化窗口
    void gradientBackGround();//控制随时间渐变色
    void loadUser();//加载用户
    QStringList getAllDir(const QString& dirPath);//获取当前目录下所有目录
protected:
    bool eventFilter(QObject *obj, QEvent *event);//解决点击下拉列表窗口移动问题
    void mousePressEvent(QMouseEvent *event);//鼠标点击
    void mouseMoveEvent(QMouseEvent *event);//鼠标移动
    void mouseReleaseEvent(QMouseEvent *event);//鼠标释放
signals:
    void loadHead(QString id);
private slots:
    void on_btn_close_clicked();

    void on_btn_min_clicked();

    void on_btn_login_clicked();

    void onTransMSG(MsgType type,QString msg);

    void deleteAccount(int i);

    void on_comboBox_currentIndexChanged(int index);

    void on_btn_reg_clicked();

    void on_username_editingFinished();

private:
    Ui::Widget *ui;
    static Widget* m_pWidget;
    QTimer m_gradientTimer;//控制渐变色的定时器
    bool isPressedWidget;//isPressedWidget和last用来控制窗口移动
    QPoint last;
    QSystemTrayIcon m_trayIcon;//系统托盘
    QMenu m_menu;//为系统托盘添加的右击菜单
    QAction m_ac1,m_ac2;//为菜单添加的菜单项
    QAction m_ac3,m_ac4,m_ac5;//为文本框添加的图标控件
    bool m_control_show;//控制显示主窗口
    ChatSocket* m_pChatSocket;
    QVector<int> m_vector;//用于控制删除账户
    QStringList m_vecname;//用于辅助填充账号密码
    QStringList m_vecpwd;//用于辅助填充账号密码
    QSignalMapper* m_mapper;//用于映射登陆框的删除按钮
    QListWidget * m_AccountList = NULL;//下拉列表框
    QString m_id;//记录用户名
};
#endif // WIDGET_H
